#include "statusmonitoringview.h"

StatusMonitoringView::StatusMonitoringView(QWidget *parent)
    : QWidget{parent}
{
    setUI();
}

StatusMonitoringView::~StatusMonitoringView()
{
      obj_timer->stop();
}

void StatusMonitoringView::setUI()
{

      topWidget = new QWidget(this);
      topWidget->setGeometry(0,0,310,124);


      gridLayout = new QGridLayout();
      gridLayout->setContentsMargins(0, 0, 0, 0);
      gridLayout->setSpacing(0);

      for (int i = 0; i < 10; i++){
          label[i] = new QLabel();
          label[i]->setSizePolicy(
              QSizePolicy::Expanding,
              QSizePolicy::Expanding
              );
          if(i != 5){
              label[i]->setScaledContents(true);
          }
          gridLayout->addWidget(label[i], i/5, i%5);

      }
      /* 将 gridLayout 设置到 gWidget */
      topWidget->setLayout(gridLayout);

      timeLabel = new QLabel(this);
      timeLabel->setObjectName("timeLabel");
      timeLabel->setGeometry(80,124,150,62);
      timeLabel->setAlignment(Qt::AlignCenter);

      timeout_slot();
      //给定时器实例化对象
      obj_timer = new QTimer(this);
      obj_timer->start(1000);
      //将定时器发射的timeout信号与自定义的槽函数进行连接
      connect(obj_timer, &QTimer::timeout, this, &StatusMonitoringView::timeout_slot);
}

void StatusMonitoringView::timeout_slot()
{
      //调用事件类中的静态成员函数获取当前的系统时间
      sys_dt = QDateTime::currentDateTime();
      //调用成员函数，将时间转换为字符串
      timeLabel->setText(sys_dt.toString("yyyy-MM-dd \n hh:mm:ss"));
}
